<!DOCTYPE html>
<html lang="en">
<head>
  
<meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>商城详情页</title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- <link rel="shortcut icon" href="http://favicon.ico"> -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">


  <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm.min.css">
  <link rel="stylesheet" href="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/css/sm-extend.min.css">
  <script type="text/javascript" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/common/common/common.js"></script>
  <style type="text/css">

    /*设置默认样式*/
    *{
      margin: 0;
      padding: 0;
    }

    /*修改标题栏颜色*/
    .bar.bar-nav {
      background-color:#fff;
    }

    /*修改标题栏字体颜色*/
    .bar.bar-nav .title {
      color: #fff;
    }
    
    /*修改工具栏背景颜色*/
    .bar.bar-tab {
      background-color: #FEEA4D;
    }
    /*修改内容区背景色*/
    
    
    /*去掉列表框的线*/
    .list-block ul:before, .list-block ul:after {
      /*background-color: #fff;*/
      display: none;
    }
    
    /*设置列表中li的样式*/
    .list-block .item-content {
/*      padding-right: 0.75rem;
      padding: 0;
      margin: 0 1.5rem;
      border-bottom: 1px dashed #89DAF5;
      z-index: 100;*/
    }

    /*设置列表框中横线*/
    .list-block .item-inner{
      /*border-bottom: 1px dashed #89DAF5;
      z-index: 100;*/
    }

    /*设置列表中显示文字的内边距*/
    /*.list-block .item-media+.item-inner {*/
      /*margin: 0 0.75rem;*/
      /*padding-left: 0.75rem;*/
    /*}*/
    
    .list-block .item-inner:after {
      display: none;
    }
    /*设置page背景色*/
    .page{
      background:#fff;
    }
    /*设置card-footer的底部边框样式*/
/*    #foot_style{
      border-bottom:1px solid #fff;
    }*/

   /*设置card的样式*/
   #card_style{
     width: 100%;
     height:auto;
     margin:0 0 0 0;
   }
    /*设置导航条图标样式*/
    .pull-left{
      padding:0.3rem 0;
    }
    .pull-right{
      padding:0.3rem 0;
    }
    /*设置list-block .item-content样式*/
    #licon{
/*      padding-left: 0.4rem;*/
      padding:0.6rem 0.4rem; 
    }
    .list-block .item-inner{
      padding: 0;
    }
    .list-block .item-title{
      width: 100%;
      white-space:normal;
    }

    /*设置图片*/
    .item-media{
      width:45%;
      height:20%;
    }
    .item-media img{
      display: block;
      width:100%;
      height:100%;
    }


    /*设置文字样式*/
    .list-block .item-subtitle{
        font-size: 0.8rem;
        white-space: normal;
        margin-top:0.8rem;
    }

    /*下载按钮样式*/
    #down{
      display: block;
      width:4.0rem;
      height:2.2rem;
      position: relative;
      margin-left:1.0rem;
    }
   .b_two{
    color:black;
    font-size:0.75rem;
    position: absolute;
    margin-top:0.5rem;
    margin-left:0.2rem;
   }
   /*收藏按钮*/
   #coll{
      width:1.9rem;
      height:1.9rem;
      position: relative;
      margin-right:12%;
   }
   #love{
     display:inline-block;
     position: absolute;
     top:0.1rem;
     left:0.05rem;
     display: none;
   }

   /*内容简介部分样式*/
 /* #padd_con{
    clear:both;

  }*/
  #padd_con h4{
    margin: 0;
    padding:0.2rem 0;
  }
  #desc p{
    margin: 0;
  }
  /*底部工具栏部分 */
  #bookfoot{
    width: 100%;
    height: 3.0rem;
    border-top:1px solid #ededee;
    position: fixed;
    bottom:0;
    z-index: 800;
  }
  #foot-left{
    width: 52%;
    height: 3.0rem;
    background-color:#fff;
    float: left;
  }
  #foot-left div{
    width: 21%;
    height: 2.8rem;
    padding-top:0.2rem;
    float: left;
    margin:0 5.5%;
    text-align: center;
  }
   #foot-left div a{
    display: block;
    width: 80%;
    margin:0 auto;
   }
  #foot-left div a img {
    display: block;
    width: 100%;
  }
   #foot-left div span{
    font-size: 14px;
    display: block;
   }



   #img_video_div{
    text-align: center;
    height:200px;
    width: 100%;
    background-color: black;
    opacity:0.9;
    padding:0;
   }
   #img_video{
      height:200px;
      width:30%;
      background-color: black;
      margin: 0 auto;
      z-index: 200;
   }
   #img_video_play{
      margin-top: 15%;
      margin-left: 7.5%;
      z-index: 221;
      width:15%;
      position: fixed;
   }

   #titlename{
    margin-left:3%;
    border:0px solid white;
    padding-bottom:0.2rem;
   }


  #foot-btn{
    width: 48%;
    height: 3.0rem;
    line-height: 3.0rem;
    background-color:#1FCA23;
    float: right;
    color: #fff;
    font-size: 16px;
    text-align: center;
  }

  </style>
</head>
<body>
  
  <div class="page-group">
    <div class="page">
      <!-- 标题栏 -->
      <!-- <header class="bar bar-nav">
           <a class=" pull-left"><img src="../img/back.png" alt=""></a>
           <a class=" pull-right"><img src="../img/cart.png" alt=""></a>
           
      </header> -->
      <!-- 内容部分 -->

      
      <div class="content">
            <div id="img_video_div" hidden>
              <img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/imgplay.png" id="img_video_play"/>
            <img src="" id="img_video"/>

            
          </div>

          <div class="card" id="card_style">
              <!-- <div class="card-header"><strong>资源介绍</strong></div> -->
              <!-- <div class="card-content" hidden id="img_video_div"> -->
                <!--  -->
              <!-- </div> -->
              
              <div class="card-content" id="titlename">
                  <div class="list-block media-list">
                    <ul>
                      <li class="item-content" id="licon">

                      </li>
                    </ul>
                  </div>
              </div>
          </div>


           
         <!-- 内容介绍部分 -->    
         <div class="content-padded" id="padd_con">
             <h4>内容简介</h4>
             <div id="desc">
             </div>   
         </div>       
     </div>
     <!-- 底部工具栏部分 -->
     <div id="bookfoot">
        <div id="foot-left">

          <div id="div_share">
             <a href="#"> <img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/imgshare.png" onclick="share()"></a>              
             <span></span>
           </div>

           <div>
             <a href="#" onclick="clkcomment()"><img src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/news.png"></a>     
             <span id="commentnum"></span>
           </div>
           
           <div>
             <a href="#"><img id="moz" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png" state="0" alt="" onclick="loveclick(this)"></a>       
             <span id="likenum"></span>
           </div>
        </div>
        <div id="foot-btn" onclick="buybook()">
          <span id="btnmoney"></span>
          <span id="judge"></span>
        </div>
     </div>            
    </div>
  </div>

  <!-- 固定的js引用，所有的jQuery 要用 $$ 表示 --> 
<script type="text/javascript" src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/jquery-1.11.1.min.js"></script>
<!-- 这一行代码是为了 避免js冲突 -->
<script type="text/javascript">var $$ =jQuery.noConflict();</script>

<script type='text/javascript' src='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/zepto/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/sm.min.js' charset='utf-8'></script>
<!-- <script type='text/javascript' src='https://gitee.com/huaflower/CommonFile/raw/master/js/sm-extend.min.js' charset='utf-8'></script> -->
<script src="https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/js/js/swiper/swiper.min.js"></script>
<script type="text/javascript">


var curgoods_id = "-1";
var curprice = -1;//当前的价格
var curtype = 0;//默认是图书详情
var curdata;//当前图书的data
var goods_name = "商品";

 // 点击评论按钮进入评论界面
 function clkcomment(){
    native_goto('local/comment?cid='+curgoods_id+'&type='+curtype);
 }

 // 遍历数据 页面
 function getData(cid){ 
    var param = {}
    if(curtype == 1){
      net_request('get','api/v1/videos/'+cid,param,successCallBack,errorCallBack);
    }else{
      net_request('get','api/v1/books/'+cid,param,successCallBack,errorCallBack);  
    }
    

 }

 // 判断当前用户是否购买
 function judgeOrder(){
   var param = {}
   var url = 'api/v1/orders?search=goods_id:'+curgoods_id+';user_id:'+curuserid+';status:1'+'&searchJoin=and';
   net_request('get',url,param,judgeOrderSuccessCallBack,errorCallBack);
 }

 // 查询该用户是否点赞
 function booklikes(){
   var param = {}
   var url = 'api/v1/user_book_likes?search=user_id:'+curuserid+';type:'+curtype+';goods_id:'+curgoods_id+';islike:1&searchJoin=and';
   net_request('get',url,param,booklikesSuccessCallBack,errorCallBack);
 }

 // 遍历数据 点赞接口
  function getlikes(){
   var param = {}
   var url = 'apis/likebook?user_id='+curuserid+'&goods_id='+curgoods_id+'&type='+curtype;
   net_request('get',url,param,getlikesSuccessCallBack,errorCallBack);
  }

  
 // 成功函数回调 判断当前用户是否购买
 function judgeOrderSuccessCallBack(data){
    
    booklikes();

    // 调用查询是否点赞函数

    if(isIOSApply == '1' && isIOS()){

     $$('#judge').html("立即下载");
     $$("#btnmoney").html("");


    }else{


       
      if (isNotNull(data) && data.success && isNotNull(data.data.total) && Number(data.data.total) > 0) {
          $$('#judge').html("立即下载");
          $$("#btnmoney").html("");
      }else{
          if(curprice == 0){//当前价格为0，可以下载
             $$('#judge').html("立即下载");
          $$("#btnmoney").html("");
          }else{
             $$('#judge').html("立即购买");
          }
          
      }


    }
   
 }

 // 成功函数回调 查询当前用户是否点赞
  function booklikesSuccessCallBack(data){

     if (isNotNull(data) && data.success) {
        var databody = data.data;
        if (isNotNull(databody)) {
          if(databody.length > 0){//证明有点赞
            $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love2.png");
          }else{
            $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png");
          }
        }  
       
     }
  }
   
 // 成功函数回调 用户点赞
 function getlikesSuccessCallBack(data){

    if (isNotNull(data) && data.success) {
        var item = data.data;
        if (isNotNull(item)) {
           var islikeitem = item.islike;
           var num = parseInt($$('#likenum').text());
           // alert(item.islike);
           if (islikeitem == 1) {
              num = num + 1;
              $$('#likenum').text(num);
              $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love2.png");
           }else{
              num = num - 1;
              $$('#likenum').text(num);
              $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png");
           }
        }
    }  
 }

 // 成功函数回调  页面
 function successCallBack(data){
   // console.log(JSON.stringify(data));
   // console.log(data);
// 调用 判断当前用户是否购买
        judgeOrder();
   
   if(isIOSApply == '1' && isIOS()){

    if (isNotNull(data) && data.success) {
      var item = data.data.book;
      curdata = data.data;
      // console.log(JSON.stringify(item));
      // console.log(item);
     // 生成新的HTML
      var html = '';
      var content = '';
      // 遍历数据                 
       if (isNotNull(item)) {


             if(isNotNull(item.likenum)){
               var itemlikenum = item.likenum;
                $$('#likenum').html(itemlikenum);
             }else{
               $$('#likenum').html("0");
             }

             if (isNotNull(item.islike) && item.islike == 1) {
                $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love2.png");
              }else{
                $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png");
              }

              if (isNotNull(item.commentnum)) {
                var itemcommentnum = item.commentnum;
                $$('#commentnum').html(itemcommentnum);
              }else{
                $$('#commentnum').html("0");
              }

              if(isNotNull(item.price)){
                 // $$("#btnmoney").html("￥"+item.price+"&emsp;");
                 curprice = item.price;
              }else{
                 curprice = 0;
              }

              if(isNotNull(item.name)){
                 goods_name = item.name;
              }

                html = `
                       <div class="item-media">
                         <img src="${item.img}" alt="">
                       </div>
                       <div class="item-inner">
                           <div class="item-title-row">
                             <div class="item-title"><strong>${item.name}</strong></div>
                           </div> 
                           <div class="item-subtitle">时期:${item.period}</div>
                           <div class="item-subtitle">科目:${item.category}</div>
                           <div class="item-subtitle" >年级:${item.grade}</div>`

                 htmlvideo = `<h4 style="padding-top:3%;padding-bottom:1%;">${item.name}</h4>`; 
                 
                 content = `<p style="text-indent:2em;">${item.desc}</p>`;

                 if (!isNotNull(item.desc)) {
                          content = "无";
                      }


             $$("#img_video").attr("src",item.img);
             $$('#licon').html(html);
             if(curtype == 1){
               $$('#titlename').html(htmlvideo);
             }
             $$('#desc').html(content);  

       }
       
                  
      
    }


    }else{


      if (isNotNull(data) && data.success) {
        var item = data.data.book;
        curdata = data.data;
        // console.log(JSON.stringify(item));
        // console.log(item);
       // 生成新的HTML
        var html = '';
        var content = '';
        // 遍历数据                 
         if (isNotNull(item)) {


               if(isNotNull(item.likenum)){
                 var itemlikenum = item.likenum;
                  $$('#likenum').html(itemlikenum);
               }else{
                 $$('#likenum').html("0");
               }

               if (isNotNull(item.islike) && item.islike == 1) {
                  $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love2.png");
                }else{
                  $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png");
                }

                if (isNotNull(item.commentnum)) {
                  var itemcommentnum = item.commentnum;
                  $$('#commentnum').html(itemcommentnum);
                }else{
                  $$('#commentnum').html("0");
                }

                if(isNotNull(item.price)){
                   //$$("#btnmoney").html("￥"+item.price+"&emsp;");
                   //暂时隐藏支付
                   $$("#btnmoney").html("");
                   curprice = item.price;
                }else{
                   curprice = 0;
                }

                if(isNotNull(item.name)){
                   goods_name = item.name;
                }

                  // html = `
                  //        <div class="item-media">
                  //          <img src="${item.img}" alt="">
                  //        </div>
                  //        <div class="item-inner">
                  //            <div class="item-title-row">
                  //              <div class="item-title"><strong>${item.name}</strong></div>
                  //            </div> 
                  //            <div class="item-subtitle">时期:${item.period}</div>
                  //            <div class="item-subtitle">科目:${item.category}</div>
                  //            <div class="item-subtitle" >年级:${item.grade}</div>
                  //            <div class="item-subtitle"style="color:red;">价格:&nbsp;&nbsp;￥${curprice}元</div>
                  //        </div>`; 

                  //暂时去掉支付
                  html = `
                         <div class="item-media">
                           <img src="${item.img}" alt="">
                         </div>
                         <div class="item-inner">
                             <div class="item-title-row">
                               <div class="item-title"><strong>${item.name}</strong></div>
                             </div> 
                             <div class="item-subtitle">时期:${item.period}</div>
                             <div class="item-subtitle">科目:${item.category}</div>
                             <div class="item-subtitle" >年级:${item.grade}</div>
                         </div>`; 


                   // htmlvideo = `
                   //             <h4 style="padding-top:3%;padding-bottom:1%;">${item.name}</h4> 
                   //             <div id="titleprice">价格:&nbsp;&nbsp;￥${curprice}元</div>
                   //            `; 

                              htmlvideo = `
                               <h4 style="padding-top:3%;padding-bottom:1%;">${item.name}</h4> 
                               
                              `; 
                   
                   content = `<p style="text-indent:2em;">${item.desc}</p>`;

                   if (!isNotNull(item.desc)) {
                            content = "无";
                        }


               $$("#img_video").attr("src",item.img);
               $$('#licon').html(html);
               if(curtype == 1){
                 $$('#titlename').html(htmlvideo);
               }
               $$('#desc').html(content);  

         }
         
                    
        
      }


    }
 }


//点击买书
 function buybook(){
    var btntext = $$('#judge').html();
    if("立即下载" == btntext){

        if(isNotNull(curdata)){
            toDownloadBook();
        }else{
           $.toast("当前图书有误，请重新打开");
        }
        


    }else if("立即购买" == btntext){

      //正在提交订单
      var param = {
        user_id:curuserid,
        goods_id:curgoods_id,
        type:curtype+"",
        status:'0',
        price:curprice+""
      }
      var url = 'api/v1/orders';
      net_request('post',url,param,orderSUccessCallBack,errorCallBack);


        
    }
 }



//订单支付成功,开始校验订单
 function orderSUccessCallBack(data){

  if(isNotNull(data) && data.success && isNotNull(data.data)){
    //正在提交订单
      var param = {}
      var url = 'apis/alipay?out_trade_no='+data.data.id+'&total_amount='+curprice+'&subject='+goods_name;
      net_request('post',url,param,verOrderSuccessBack,errorCallBack);

  }else{
    native_showtoast("订单提交失败");
  }
  

 }



function verOrderSuccessBack(data){
  //返回校验订单的信息，需要传给客户端
  // if(isNotNull(data) && data.success){
      $.toast("正在跳转支付，请稍等");

        var param = {
            type:'buybook',
            bookdata:JSON.stringify(data)
        };
        //开始请求购买图书
        send_data(param);  
  // }else{
  //   native_showtoast("支付失败");
  // }
}


//去下载图书
function toDownloadBook(){
  $$('#judge').html("立即下载");
  $$("#btnmoney").html("");
  curdata.booktype = curtype+"";//设置当前的图书类型，0：图书，1：视频
  var param = {
            type:'download_book',
            bookdata:JSON.stringify(curdata)
        };
        //开始加载到本地下载图书
        send_data(param);
}


//分享
 function share(){
    native_goto("local/share_html");
 }

 // 失败函数回调
 function errorCallBack(data){
   console.log(JSON.stringify(data));
 }

  function getParams(data){
   // data需要转成json调用 ，函数urlParamParseJson();
     var jodata = urlParamParseJson(data);
     if(isNotNull(jodata) && (jodata.type == "0" || jodata.type == 0)){//图书
        curtype = 0;
     }else if(isNotNull(jodata) && (jodata.type == "1" || jodata.type == 1)){//视频
        curtype = 1;
     }

     if(curtype == 0){//图书
        $$("#img_video_div").hide();
     }else if(curtype == 1){//视频
        $$("#img_video_div").show();
     }

     if(isNotNull(jodata) && isNotNull(jodata.cid)){//
        curgoods_id = jodata.cid;
        getData(jodata.cid);
        

     }



  }

   // 点击出现收藏或取消收藏事件
   function loveclick(cthis) {

    // 调用 用户点赞函数
     getlikes();
     
     // var state = Number($$('#moz').attr("state"));
     // if(state == 0){
     //    $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love2.png");
     //    $$('#moz').attr("state","1");
     // }else{
     //    $$('#moz').attr("src","https://gitee.com/huaflower/ReadBook_CommonFile/raw/master/img/img/love.png");
     //    $$('#moz').attr("state","0");
     // } 

   }

    // 初始化
    $(function(){

      if(isIOSApply == '1' && isIOS()){
         $$("#div_share").hide();
      }

      $.init();
    });
  </script>
</body>
</html>